package com.cloudwebrtc.voip.mediaengine.impl;

import com.cloudwebrtc.voip.mediaengine.CallStatistics;
import com.cloudwebrtc.voip.mediaengine.VideoStream;
import com.cloudwebrtc.voip.mediaengine.VideoStreamObserver;

public class VideoStreamImpl implements VideoStream {
	//implement for VideoStream_JNI.cpp
	private long nativePtr = 0;
	private native int StartSending(long nativePtr);
	private native boolean IsSending(long nativePtr);
	private native int StopSending(long nativePtr);
	private native int StartReceiving(long nativePtr);
	private native boolean IsReceiving(long nativePtr);
	private native int StopReceiving(long nativePtr);
	private native int SetupVideoStream(long nativePtr,int camera_index, long local_window_id,
			long remote_window_id, int rotation, int width, int height,
			int bitrate, int fps);
	private native int RegisterVideoStreamObserver(long nativePtr, VideoStreamObserver cb);
	private native int DeRegisterVideoStreamObserver(long nativePtr);
	private native int ChangeCaptureVideoSize(long nativePtr, short width, short height);
	private native int ChangeSendBitRate(long nativePtr, int bitrate);
	private native int ChangeCamera(long nativePtr,int camera_index, int rotation_new,
			Object local_window_id);
	private native int ChangeRemoteRender(long nativePtr,Object remote_window_id);
	private native int ChangeLocalRender(long nativePtr,Object local_window_id);
	private native int GetCaptureRotation(long nativePtr);
	private native int ChangeCaptureRotation(long nativePtr,int rotation);
	private native int GetCallStatisticsFractionLost(long nativePtr);
	private native int GetCallStatisticsRttMs(long nativePtr);
	
	public VideoStreamImpl(long aNativePtr)
	{
		nativePtr = aNativePtr;
	}

	@Override
	public int SetupVideoStream(int camera_index, long local_window_id,
			long remote_window_id, int rotation, int width, int height,
			int bitrate, int fps) {
		return SetupVideoStream(nativePtr,camera_index,local_window_id,remote_window_id,rotation,width,height,bitrate,fps);
	}

	@Override
	public int StartSending() {
		return StartSending(nativePtr);
	}

	@Override
	public boolean IsSending() {
		return IsSending(nativePtr);
	}

	@Override
	public int StopSending() {
		return StopSending(nativePtr);
	}

	@Override
	public int StartReceiving() {
		return StartReceiving(nativePtr);
	}

	@Override
	public boolean IsReceiving() {
		return IsReceiving(nativePtr);
	}

	@Override
	public int StopReceiving() {
		return StopReceiving(nativePtr);
	}

	@Override
	public int RegisterVideoStreamObserver(VideoStreamObserver cb) {
		return RegisterVideoStreamObserver(nativePtr,cb);
	}
	
	@Override
	public int DeRegisterVideoStreamObserver() {
		return DeRegisterVideoStreamObserver(nativePtr);
	}

	@Override
	public int ChangeCaptureVideoSize(short width, short height) {
		return ChangeCaptureVideoSize(nativePtr,width,height);
	}

	@Override
	public int ChangeSendBitRate(int bitrate) {
		return ChangeSendBitRate(nativePtr,bitrate);
	}

	@Override
	public int ChangeCamera(int camera_index, int rotation_new,
			Object local_window_id) {
		return ChangeCamera(nativePtr,camera_index,rotation_new,local_window_id);
	}

	@Override
	public int ChangeRemoteRender(Object remote_window_id) {
		return ChangeRemoteRender(nativePtr,remote_window_id);
	}

	@Override
	public int ChangeLocalRender(Object local_window_id) {
		return ChangeLocalRender(nativePtr,local_window_id);
	}

	@Override
	public int GetCaptureRotation() {
		return GetCaptureRotation(nativePtr);
	}

	@Override
	public int ChangeCaptureRotation(int rotation) {
		return ChangeCaptureRotation(nativePtr,rotation);
	}
	
	@Override
	public CallStatistics GetCallStatistics()
	{
		CallStatistics stats = new CallStatistics();
		stats.fractionLost = GetCallStatisticsFractionLost(nativePtr);
		stats.rttMs = GetCallStatisticsRttMs(nativePtr);
		return stats;
	}

}
